//
//  RKBaseCtrl.swift
//  RKTemplate
//
//  Created by zhaoke on 2023/7/23.
//

import UIKit

class RKBaseCtrl: UIViewController {
    override func viewDidLoad() {
        view.backgroundColor = r_bgColor
    }
    // 自定义返回按钮
    func setUpBackBtnItem() {
        if navigationController!.viewControllers.count > 1 {
            let baseBackBtnItem = UIBarButtonItem(image: UIImage(named: "e_back_btn"), style: .plain, target: self, action: #selector(backAction))
            navigationItem.leftBarButtonItem = baseBackBtnItem
        } else {
            navigationItem.leftBarButtonItem = nil;
        }
    }
    // Back Action
    @objc func backAction() {
       navigationController?.popViewController(animated: true)
    }
    //
    func setRightTitle(title: String) {
        let barItem = UIBarButtonItem(title: title, style: .plain, target: self, action:#selector(rightItemAction(sender:)))
        navigationController?.navigationItem.rightBarButtonItem = barItem
    }
    func setRightImage(imageName: String) {
        let barItem = UIBarButtonItem(image: UIImage(named: imageName), style: .plain, target: self, action: #selector(rightItemAction(sender:)))
        navigationController?.navigationItem.rightBarButtonItem = barItem
    }
    @objc func rightItemAction(sender: UIBarButtonItem) {}
}
extension RKBaseCtrl {
    override func didMove(toParent parent: UIViewController?) {
        super.didMove(toParent: parent)
        if parent == nil {
            self.realityBackAction()
        }
    }
    // 页面真正返回(侧滑、back)处理 子类重新此方法
    func realityBackAction() { }
}
